Repository navigation
feat(toggle): add custom checkedIcon and uncheckedIcon support - #31020
AbdullahAhmadAAK wants to merge 2 commits into
Conversation
|
@AbdullahAhmadAAK is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
| } | ||
|
|
||
| .toggle-inner .toggle-switch-icon { | ||
| @include padding(1px); |
| min-width: var(--on-off-label-icon-size); | ||
| min-height: var(--on-off-label-icon-size); | ||
| display: block; | ||
| opacity: 0.86; | ||
| transition: transform $toggle-md-transition-duration, opacity $toggle-md-transition-duration, color $toggle-md-transition-duration; |
There was a problem hiding this comment.
was there a reason to include min-{width,height}, display, opacity and transition, though? It should've been already styled as icon support was already there.
|
|
||
|
|
| <div class="grid-item"> | ||
| <h2>Unchecked</h2> | ||
| <ion-toggle>Enable Notifications</ion-toggle> | ||
| <ion-toggle >Enable Notifications</ion-toggle> |
|
Hi @NyaomiDEV , I've made the required changes according to your review. |
|
It would look good to me, however I think the Ionic team should check it too. |
|
Hey @AbdullahAhmadAAK! Thanks for the PR! I've opened #31774 to carry this forward, so I'm going to close this one in favor of it. New features now go to the Thanks again for getting this started! 💪 |
Issue number: resolves #30996 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Currently, the on/off label icons in `ion-toggle` are hardcoded per mode, so there's no way to swap them for something like a sun and moon on a dark mode toggle. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Added `checkedIcon` and `uncheckedIcon` props to `ion-toggle`, plus `toggleCheckedIcon` and `toggleUncheckedIcon` global config options. The props win over the config, and both fall back to the existing mode defaults. Like the defaults, they only show when `enableOnOffLabels` is `true`. - In `ios`, the default checked icon is a dash rotated into a vertical line, so a custom checked icon skips that rotation and uses the same size and inset as the unchecked icon. - Added both props to the standalone Angular `IonToggle` inputs, since those aren't generated. ## Does this introduce a breaking change? - [ ] Yes - [X] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> It's a new feature, which is why it's pointed at `feature-9.1`. ## Other information This is based on [the original PR](#31020) by @AbdullahAhmadAAK. That PR pointed at `main`, but new features now go to `feature-9.1`, a branch that didn't exist yet when it was opened. Retargeting it would have conflicted, because the generated Angular proxies moved on `feature-9.1`, so I remade it from `feature-9.1` instead. Their commit is still there with them as the author. The commits after it fix the `ios` checked icon size, keep the `md` icon at its current size and add tests. Thanks to @AbdullahAhmadAAK for getting this started! [Custom icons test page (MD)](https://ionic-framework-git-fw-7639-ionic1.vercel.app/src/components/toggle/test/custom-icons?ionic:mode=md) [Custom icons test page (iOS)](https://ionic-framework-git-fw-7639-ionic1.vercel.app/src/components/toggle/test/custom-icons?ionic:mode=ios) --------- Co-authored-by: AbdullahAhmadAAK <Abdullahaak06@gmail.com> Co-authored-by: ionitron <hi@ionicframework.com>
Issue number: resolves #30996
What is the current behavior?
ion-toggleuses fixed built-in on/off icons whenenableOnOffLabelsis enabled, and there is no way to override those icons globally or per component instance.What is the new behavior?
This PR adds customizable toggle icons with a clear fallback order:
checkedIconanduncheckedIconon [ion-toggle].toggleCheckedIconandtoggleUncheckedIconDoes this introduce a breaking change?
This is a non-breaking feature enhancement focused on toggle icon customization and test coverage only.
Screenshot of how it looks

Video : https://github.com/user-attachments/assets/a8a103dc-d6b1-4b81-be65-baa5b476a379